﻿using System;
using System.Collections;
using System.Linq;
using System.Windows;
using System.Windows.Media;

namespace Charts.Converters
{
	public class PointsConverter : MultiValueConverterBase<PointsConverter>
	{
		public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			try {
				
				double h = (double)values[0];
				double w = (double)values[1];
				
				double max = (double)values[2];
				double min = (double)values[3];
				
				IList list = (IList)values[4];
				
				int n = list.Count;
				
				var q = Enumerable
					.Range(0, n)
					.Select(i => new Point(
						w * ((double)0.5 + i) / n,
						h * (max - System.Convert.ToDouble(list[i])) / (max - min)
					));
				
				var points = new PointCollection(q);
				
				return points;
				
			} catch (Exception) { return DependencyProperty.UnsetValue; }
		}
	}
}
